﻿@{
    ViewBag.Title = "用户列表";
    Layout = "~/Views/Shared/_LayoutList.cshtml"; 
}
@(      
 Html.DWZGridFor<V_RoleUserRelation>()
    .ID("UserInfoList")
    .Action(@Url.Action("RoleUserRelationList"))
    .Height("document.documentElement.clientHeight-86")
    .ExtParam(new { RoleCode = @ViewBag.RoleCode })
    .Columns(col =>
    {
        col.Bind(e => e.Id).IsKey();
        col.Bind(e => e.UserCode).Width(80).AsQuery().Align(FlexiGridAlign.Left);
        col.Bind(e => e.UserName).Width(80).AsQuery().Align(FlexiGridAlign.Left);
        col.Bind(e => e.AccountState).EnumKey("AccountState").Width(60);
        col.Bind(e => e.OrgName).Width("auto").Align(FlexiGridAlign.Left);
        col.Bind(e => e.SeqNo).Width(40);
    })
    .Buttons(btn =>
    {
        btn.Bind("Add", "新建用户", FlexiGridButtonType.Add).OnPress("AddUser");
        btn.Bind("Del", "删除用户", FlexiGridButtonType.delete).OnPress("DelUser");
    })
)
@Html.Css("dailog")
@Html.Js("dailog")
<script type="text/javascript">
    // 添加用户信息
    function AddUser(id) {
        OpenModalDialog("@Url.Action("SetRoleUser", new { mode = 2 })", { caption: "选择角色用户", width: 430, height: 250, onclose: selectuser_callback }); 
    }

     function selectuser_callback(users) 
     {
        if (users && users.length > 0) 
        {
            var userids = users.join(",");
            $.ajax({
                type: "POST",
                url: '@Url.Action("AddRoleUser")',
                data: { "roleCode": '@ViewBag.RoleCode',"userids": userids},
                dataType: "json",
                success: function(data) 
                {
                    if (data.IsSuccess) 
                    {                            
                        showLoadingMsg(data.Msg, { left: 330, top: 1 },true,3000);
                        $("#UserInfoList").flexReload();                              
                    }
                    else 
                    {                               
                        hideLoadingMsg();
                        showErrorTip(data.Msg, {left:330,top:1}, true, 5000);
                    }
                }
            }); //end if $.ajax 
        }
    }

    function DelUser() 
    {
        var ids = $("#UserInfoList").getCheckedRows(); 
        if(ids.length==0)
        {
            showErrorTip("请选择需要移除的用户", {left:300,top:1}, true, 3000);
            return;
        }
        if(confirm("请确定要从角色中移除这"+ids.length+"个用户吗?")) 
        {
            var userids = ids.join(",");
            var roleID= '@ViewBag.RoleCode';
            $.ajax({
                    type: "POST",
                    url: '@Url.Action("DeleteRoleUser")',
                    data: { "RoleCode": roleID,"userids": userids},
                    dataType: "json",
                    success: function(data) {
                        if (data.IsSuccess) {                            
                            showLoadingMsg(data.Msg, { left: 300, top: 1 },true,3000);
                            $("#UserInfoList").flexReload();                              
                        }
                        else {                               
                            hideLoadingMsg();
                            showErrorTip(data.Msg, {left:300,top:1}, true, 5000);
                        }
                    }
                }); //end if $.ajax
        }
    }
</script>
